#!/bin/bash
# -*- sh -*-
#
# $Id$
#
# Script to monitor absolute disk usage.
#
# Parameters understood:
#
#       config   (required)
#       autoconf (optional - used by munin-config)
#
# Environment
#       exclude: space separated list if fs types to exclude.
#                iso9660 by default
#       warning: Warning _percentage_, default 92
#       critical: Critical _percentage_, default 98
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
# $Id$
#
#%# family=manual
#%# capabilities=autoconf

. $MUNIN_LIBDIR/plugins/plugin.sh

if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi

exclude=${exclude:-iso9660}

exclude=$(echo $exclude | sed -e 's/ +/ -x /g' -e 's/^/-x /')

if [ "$1" = "config" ]; then

        echo 'graph_title Filesystem usage (in bytes)'
        echo 'graph_args --base 1024 --lower-limit 0'
        echo 'graph_vlabel bytes'
        echo 'graph_category disk'
        echo 'graph_total Total'
        df -P -l $exclude | sed 1d | grep -v "//" |
        while read dev size used avail cap mnt; do
                name="$(clean_fieldname $dev)"
                echo "$name.label $mnt"
                echo "$name.cdef $name,1024,*"
                warn=$(get_warning $name)
                crit=$(get_critical $name)
                if [ -n "$warn" ]; then
                        echo "$name.warning $((size * $warn / 100))"
                fi
                if [ -n "$crit" ]; then
                        echo "$name.critical $((size * $crit / 100))"
                fi
        done
        exit 0
fi

df -P -l $exclude | sed 1d | grep -v "//" |
   while read dev size used avail cap mnt; do
        echo "$(clean_fieldname $dev).value $used"
done
